﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import Modules.minigames.*;
    import Display.aswingui.*;
    import Display.MarketUI.assets.*;

    public class HUDMiniGameComponent extends HUDComponent implements IPlayerStateObserver {

        private var m_iconHolder:AssetPane;
        private var m_heartText:JTextField;
        private var m_heartText2:JTextField;
        private var m_locked:Boolean = false;
        private var m_created:Boolean = false;

        public function HUDMiniGameComponent(){
            this.visible = false;
            Global.player.addObserver(this);
            this.reset();
        }
        override public function reset():void{
            this.m_locked = false;
            if (Global.player.level < 5){
                this.m_locked = true;
            };
            if (((!(this.m_locked)) && (!(this.m_created)))){
                this.create();
                this.m_created = true;
            };
        }
        private function create():void{
            m_jWindow = new JWindow(this);
            m_jPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, true);
            _local1.align = TextFormatAlign.RIGHT;
            this.addEventListener(MouseEvent.CLICK, this.onMouseClick, false, 0, true);
            m_jPanel.append(ASwingHelper.verticalStrut(0));
            this.m_heartText = ASwingHelper.makeTextField("0", EmbeddedArt.TITLE_FONT, 16, EmbeddedArt.titleColor, 3);
            this.m_heartText.filters = EmbeddedArt.newtitleFilters;
            this.m_heartText2 = ASwingHelper.makeTextField(CardUtil.formatTime(30), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 16, 0xFFFFFF, 0, _local1);
            LoadingManager.load(Global.getAssetURL("assets/hud/Mini_Game/slices_bg.png"), this.onIconLoaded);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            _local2.append(ASwingHelper.verticalStrut(-4));
            _local3.append(this.m_heartText);
            _local2.append(_local3);
            m_jPanel.append(_local2);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local4.append(ASwingHelper.verticalStrut(40));
            _local5.append(this.m_heartText2, BorderLayout.CENTER);
            _local4.append(_local5);
            m_jPanel.append(_local4);
            m_jWindow.setContentPane(m_jPanel);
            ASwingHelper.prepare(m_jWindow);
            m_jWindow.cacheAsBitmap = true;
            m_jWindow.show();
            this.alpha = 0;
            if (!this.m_locked){
                Z_TweenLite.to(this, 1, {alpha:1});
                this.addTooltip();
                this.addCounter();
            };
        }
        private function onIconLoaded2(_arg1:Event):void{
            var _local3:Bitmap;
            var _local4:Bitmap;
            var _local2:Loader = (_arg1.target.loader as Loader);
            if ((_local2.content is Bitmap)){
                _local3 = (_local2.content as Bitmap);
                _local4 = (_local2.content as Bitmap);
                _local4.x = 9;
                _local4.y = 22;
                addChildAt(_local4, 1);
                ASwingHelper.prepare(m_jWindow);
            };
        }
        private function onIconLoaded(_arg1:Event):void{
            var _local3:Bitmap;
            var _local4:Bitmap;
            var _local2:Loader = (_arg1.target.loader as Loader);
            if ((_local2.content is Bitmap)){
                _local3 = (_local2.content as Bitmap);
                _local4 = (_local2.content as Bitmap);
                _local4.x = 0;
                _local4.y = 12;
                addChildAt(_local4, 0);
                m_jPanel.setPreferredSize(new IntDimension(_local4.width, (_local4.height + 12)));
                m_jPanel.setMinimumSize(new IntDimension(_local4.width, (_local4.height + 12)));
                m_jPanel.setMaximumSize(new IntDimension(_local4.width, (_local4.height + 12)));
                ASwingHelper.prepare(m_jWindow);
            };
            LoadingManager.load(Global.getAssetURL("assets/hud/Mini_Game/slices_icon_energyGuy.png"), this.onIconLoaded2);
        }
        private function onMouseClick(_arg1:Event):void{
        }
        private function addTooltip():void{
        }
        private function addCounter():void{
        }
        override public function updateCounter(... _args):void{
            var _local2:MiniGame;
            if (_args[0] != -1){
                if (this.m_heartText2){
                    this.m_heartText2.setText(CardUtil.formatTime((30 - (_args[0] as int))));
                    if (this.m_heartText2.getText() != "0"){
                        this.visible = true;
                    };
                } else {
                    this.visible = false;
                };
            } else {
                _local2 = MiniGame.getMiniGame();
                if (((!((_local2 == null))) && (_local2.isActive()))){
                    this.visible = true;
                    if (this.m_heartText){
                        this.m_heartText.setText((_local2.getScore() + " "));
                    };
                } else {
                    this.visible = false;
                };
            };
            ASwingHelper.prepare(m_jWindow);
        }
        public function levelChanged(_arg1:int):void{
        }
        public function xpChanged(_arg1:int):void{
        }
        public function commodityChanged(_arg1:int, _arg2:String):void{
        }
        public function energyChanged(_arg1:Number):void{
        }
        public function goldChanged(_arg1:int):void{
        }
        public function cashChanged(_arg1:int):void{
        }

    }
}//package Display.hud.components 
